import { defineStore } from 'pinia'

import { postPageListData, deletePageById } from '@/service/main/system/system'
import { MockPageList } from '@/mock/system'

interface IsystemState {
  pageList: any[]
  pageTotalCount: number
}

export const useMainStore = defineStore('system', {
  state: (): IsystemState => {
    return {
      pageList: [],
      pageTotalCount: 0,
    }
  },
  actions: {
    async postPageListAction(pageName: string, queryInfo: any) {
      // 正常请求接口的代码
      // const pageListResult = await postPageListData(pageName, queryInfo)
      // const { totalCount, list } = pageListResult.data
      // this.pageList = list
      // this.pageTotalCount = totalCount

      const { totalCount, list } = MockPageList
      this.pageList = list
      this.pageTotalCount = totalCount
    },
    // 删除数据
    async deletePageByIdAction(pageName: string, id: number) {
      // const pageListResult = await deletePageById(pageName, id)
      // 删除完成后刷新页面
      this.postPageListAction(pageName, { size: 10, offset: 0 })
    },
  },
})

export default useMainStore
